package com.lrkj.property.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.property.domain.CommunityParam;
import com.lrkj.property.service.ICommunityParamService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 小区参数Controller
 *
 * @author yajun_ren
 * @date 2022-03-28
 */
@RestController
@RequestMapping("/property/communityParam")
@Api(tags = "小区参数")
public class CommunityParamController extends BaseController
{
    @Autowired
    private ICommunityParamService communityParamService;

    /**
     * 查询小区参数列表
     */
    @ApiOperation(value = "查询小区参数列表", notes = "查询小区参数列表")
    @GetMapping("/list")
    public TableDataInfo list(CommunityParam communityParam)
    {
        startPage();
        this.changeParameter(communityParam.getParams());
        List<CommunityParam> list = communityParamService.selectCommunityParamList(communityParam);
        return getDataTable(list);
    }

    /**
     * 导出小区参数列表
     */
	@ApiOperation(value = "导出小区参数列表", notes = "导出小区参数列表")
    @Log(title = "小区参数", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CommunityParam communityParam)
    {
        List<CommunityParam> list = communityParamService.selectCommunityParamList(communityParam);
        ExcelUtil<CommunityParam> util = new ExcelUtil<CommunityParam>(CommunityParam.class);
        return util.exportExcel(list, "小区参数数据");
    }

    /**
     * 获取小区参数详细信息
     */
	@ApiOperation(value = "获取小区参数详细信息", notes = "获取小区参数详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(communityParamService.selectCommunityParamById(id));
    }

    /**
     * 新增小区参数
     */
    @ApiOperation(value = "新增小区参数", notes = "新增小区参数")
    @Log(title = "小区参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityParam communityParam)
    {
        return toAjax(communityParamService.insertCommunityParam(communityParam));
    }

    /**
     * 修改小区参数
     */
    @ApiOperation(value = "修改小区参数", notes = "修改小区参数")
    @Log(title = "小区参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityParam communityParam)
    {
        return toAjax(communityParamService.updateCommunityParam(communityParam));
    }


    /**
     * 新增or修改小区参数
     */
    @ApiOperation(value = "新增or修改小区参数", notes = "新增or修改小区参数")
    @Log(title = "小区参数", businessType = BusinessType.INSERT)
    @PostMapping("/saveOrUpdate")
    public AjaxResult saveOrUpdate(@RequestBody CommunityParam communityParam)
    {
        return toAjax(communityParamService.saveOrUpdate(communityParam));
    }


    /**
     * 删除小区参数
     */
    @ApiOperation(value = "删除小区参数", notes = "删除小区参数")
    @Log(title = "小区参数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(communityParamService.deleteCommunityParamByIds(ids));
    }
}
